/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.                       */
/*                                                                            */
/*  NAME      = db2_obj.c                                                     */
/*  NOTE      = TDS 请求解析                                                  */
/*  DATE      = 2015/03/19 by zhengxd                                         */
/******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include "db2_obj.h"

/*******************************************************************************
*  FUNC     :  取得TYPDEFNAM
*  ARGS     :  p_st_private (DB2是有数据)
*           :  i_whole_flg(packet是否完整)
*           :  i_obj_ddm_flg(DB2_DDM/DB2_OBJ)
*           :  pp_typdefnam(出力type define name)
*  RTN      :  APM_L7_ANALYZE_SUCC  (success)
*              APM_L7_ANALYZE_TODO  (more data)
*              APM_L7_ANALYZE_FAIL  (failed)
*  NOTE     :
*******************************************************************************/
int db2_get_typdefnam_obj(L7session_db2_private *p_st_private
                         , int i_whole_flg
                         , int i_obj_ddm_flg
                         , char **pp_typdefnam)
{
    int i_ret = APM_L7_ANALYZE_SUCC;
    L7session_db2 *p_st_sess = p_st_private->p_st_sess;
    L7_fragment_db2 *p_st_fragment = p_st_private->p_st_fragment;
    Frbyte_Packet *p_st_data = p_st_fragment->p_st_data;

    /* DDM */
    if (i_obj_ddm_flg == DB2_DDM)
    {
        /* 取得DDM TYPDEFNAM */
        i_ret = db2_get_chrstrdr(p_st_data, p_st_fragment->ui_left_ddm_len
                                , i_whole_flg, p_st_sess->arr_ccsid
                                , pp_typdefnam, &p_st_fragment->ui_left_ddm_len);
        if (i_ret != APM_L7_ANALYZE_SUCC)
        {
            return i_ret;
        }
        p_st_fragment->i_req_resp_cp = DRDA_CP_NULL;
    }
    else
    {
        /* 取得OBJECT TYPDEFNAM */
        i_ret = db2_get_chrstrdr(p_st_data, p_st_fragment->ui_left_obj_len
                                , i_whole_flg, p_st_sess->arr_ccsid
                                , pp_typdefnam, &p_st_fragment->ui_left_obj_len);
        if (i_ret != APM_L7_ANALYZE_SUCC)
        {
            return i_ret;
        }
        p_st_fragment->i_obj_cp = DRDA_CP_NULL;
    }

    return APM_L7_ANALYZE_SUCC;
}
